package com.sdwl.imchat.config;

import com.alibaba.cloud.context.utils.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.sdwl.imchat.normal.ServiceNormalResult;
import com.sdwl.imchat.util.RedisCacheUtil;
import com.sdwl.imchat.util.enums.AppApiConstant;
import com.sdwl.imchat.util.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Order(1)
@Component
public class ApplicationRunnerInit implements ApplicationRunner {

    @Autowired
    private RedisCacheUtil redisUtil;

    @Resource
    BaseConfigBean baseConfigBean;

    @Override
    public void run(ApplicationArguments args) throws Exception {
//        查询平台的万能验证,并存在redis里面
        log.info("---------------项目启动后执行---------------");
        //获取平台万能验证码
//        String smsResult = HttpUtil.sendGet(baseConfigBean.getIpAddress() + AppApiConstant.ConfigManage.config_smsCode + AppApiConstant.config_smsCode);
//        log.info("打印一下获取万能验证码结果为:{}",smsResult);
//        if(StringUtils.isNotEmpty(smsResult)){
//            ServiceNormalResult serviceNormalResult = JSONObject.parseObject(smsResult, ServiceNormalResult.class);
//            if(200==serviceNormalResult.getCode()&&StringUtils.isNotEmpty(serviceNormalResult.getData())){
//                redisUtil.setCacheObject(AppApiConstant.config_smsCode,serviceNormalResult.getData());
//                log.info("启动初始化,万能验证码:{}已存入redis",serviceNormalResult.getData());
//            } else {
//              log.info("启动初始化,获取不到万能验证码!");
//            }
//        }
//
//        //获取平台万能验证码
//        String imResult = HttpUtil.sendGet(baseConfigBean.getIpAddress() + AppApiConstant.ConfigManage.config_smsCode + AppApiConstant.config_smsCode);
//        log.info("打印一下获取万能验证码结果为:{}",smsResult);
//        if(StringUtils.isNotEmpty(smsResult)){
//            ServiceNormalResult serviceNormalResult = JSONObject.parseObject(smsResult, ServiceNormalResult.class);
//            if(200==serviceNormalResult.getCode()&&StringUtils.isNotEmpty(serviceNormalResult.getData())){
//                redisUtil.setCacheObject(AppApiConstant.config_smsCode,serviceNormalResult.getData());
//                log.info("启动初始化,万能验证码:{}已存入redis",serviceNormalResult.getData());
//            } else {
//                log.info("启动初始化,获取不到万能验证码!");
//            }
//        }
    }
}
